package com.lighthouse.repo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lighthouse.common.TreeSelectKnowledge;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.lighthouse.repo.domain.KnowledgeRepoBaseInfo;
import com.lighthouse.repo.service.IKnowledgeRepoBaseInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 目录信息Controller
 *
 * @author ysz
 * @date 2023-05-05
 */
@RestController
@RequestMapping("/knowledge/repo")
public class KnowledgeRepoBaseInfoController extends BaseController {
    @Autowired
    private IKnowledgeRepoBaseInfoService knowledgeRepoBaseInfoService;

    /**
     * 查询目录信息列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:repo:list')")
    @GetMapping("/list")
    public TableDataInfo list(KnowledgeRepoBaseInfo knowledgeRepoBaseInfo) {
        startPage();
        List<KnowledgeRepoBaseInfo> list = knowledgeRepoBaseInfoService.selectKnowledgeRepoBaseInfoList(knowledgeRepoBaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出目录信息列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:repo:export')")
    @Log(title = "目录信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KnowledgeRepoBaseInfo knowledgeRepoBaseInfo) {
        List<KnowledgeRepoBaseInfo> list = knowledgeRepoBaseInfoService.selectKnowledgeRepoBaseInfoList(knowledgeRepoBaseInfo);
        ExcelUtil<KnowledgeRepoBaseInfo> util = new ExcelUtil<KnowledgeRepoBaseInfo>(KnowledgeRepoBaseInfo.class);
        util.exportExcel(response, list, "目录信息数据");
    }

    /**
     * 获取目录信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('knowledge:repo:query')")
    @GetMapping(value = "/{repoId}")
    public AjaxResult getInfo(@PathVariable("repoId") String repoId) {
        return success(knowledgeRepoBaseInfoService.selectKnowledgeRepoBaseInfoByRepoId(repoId));
    }

    /**
     * 新增目录信息
     */
    @PreAuthorize("@ss.hasPermi('knowledge:repo:add')")
    @Log(title = "目录信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KnowledgeRepoBaseInfo knowledgeRepoBaseInfo) {
        return toAjax(knowledgeRepoBaseInfoService.insertKnowledgeRepoBaseInfo(knowledgeRepoBaseInfo));
    }

    /**
     * 修改目录信息
     */
    @PreAuthorize("@ss.hasPermi('knowledge:repo:edit')")
    @Log(title = "目录信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KnowledgeRepoBaseInfo knowledgeRepoBaseInfo) {
        return toAjax(knowledgeRepoBaseInfoService.updateKnowledgeRepoBaseInfo(knowledgeRepoBaseInfo));
    }

    /**
     * 删除目录信息
     */
    @PreAuthorize("@ss.hasPermi('knowledge:repo:remove')")
    @Log(title = "目录信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{repoIds}")
    public AjaxResult remove(@PathVariable String[] repoIds) {
        return toAjax(knowledgeRepoBaseInfoService.deleteKnowledgeRepoBaseInfoByRepoIds(repoIds));
    }

    /**
     * 查询目录信息列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:repo:list')")
    @GetMapping("/tree")
    public TableDataInfo tree() {
        startPage();
        List<TreeSelectKnowledge> list = knowledgeRepoBaseInfoService.selectKnowledgeRepoBaseInfoTree();
        return getDataTable(list);
    }
}
